package jm.demo.script.groovy;

import groovy.lang.GroovyClassLoader;

import java.io.IOException;

import jm.demo.auth.domain.UserInterface;

import org.apache.commons.io.IOUtils;
import org.springframework.core.io.ClassPathResource;



public class First {
    static GroovyClassLoader gcl = new GroovyClassLoader();

    @SuppressWarnings("rawtypes")
    public static Class loadClass(String clazz_path) throws IOException {
        ClassPathResource resource = new ClassPathResource(clazz_path);
        String code = IOUtils.toString(resource.getInputStream(), "UTF-8");
        System.out.println(code);
        return gcl.parseClass(code, "SomeName.groovy");
        
    }
    
    @SuppressWarnings("rawtypes")
    public static void testClassLoader_loadInterface() throws Exception {
        Class clazz = loadClass("groovy/User.groovy");
        Object aScript = clazz.newInstance();
        UserInterface user = (UserInterface) aScript;
        System.out.println(user.getId());
        System.out.println(clazz.getName());
        
    }
    
    
    /**
     * @param args
     */
    public static void main(String[] args) {
        try {
            testClassLoader_loadInterface();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        

    }

}
